<?php

if (!defined('BASEPATH'))
    exit('No direct script access allowed');

class mmanufacturer extends CI_Model {

    var $theme_data = array(
        'layout_main' => 'layout',
        'left' => 'include/leftcp',
    );
    public $mytable = "manufacturer";
    public $primaryKey = "MAN_ID";
    public $resCode = "MANUFACTURER";

    function __construct() {
        parent::__construct();
    }

    function field() {
		$fieldData = array();
		$fieldData['MAN_NAME'] = '';
		$fieldData['MAN_CONTENT'] = '';
		$fieldData['MAN_LINK'] = '';
		$fieldData['MAN_STATUS'] = 1;
		$fieldData['MAN_ORDER'] = 0;
		$fieldData['MAN_THUMB'] = '';
		$fieldData['MAN_CODE'] = '';
		$fieldData['MAN_ADDR'] = '';
		$fieldData['MAN_PHONE'] = '';
		$fieldData['MAN_COMPANY_NAME'] = '';
		$fieldData['SEO_H1'] = '';
		$fieldData['SEO_KEYWORD'] = '';
		$fieldData['SEO_DESCRIPTION'] = '';
		$fieldData['SEO_METATITLE'] = '';
		$fieldData['MAN_TIME_CREATE'] = time();
		$fieldData['MAN_TIME_UPDATE'] = time();
		return $fieldData;
    }

    function get($val = '', $param = null) {
        if ($param == null)
            $param = $this->primaryKey;

        if (is_array($val) && $val != array())
            $this->db->where($val);
        else if ($val != '')
            $this->db->where($param, $val);

        $this->db->from($this->mytable);
        return $this->db->get()->first_row();
    }

    function gets($val = '', $param = null) {
        if ($param == null)
            $param = $this->primaryKey;
        if (is_array($val) && $val != array())
            $this->db->where($val);
        else if ($val != '')
            $this->db->where($param, $val);

        $this->db->from($this->mytable);
        return $this->db->get()->result();
    }

    function where_in($val = '', $param = null) {
        if ($param == null)
            $param = $this->primaryKey;

        $this->db->from($this->mytable);
        if ($val != '')
            $this->db->where_in($this->mytable . "." . $param, $val);
        return $this->db->get()->result();
    }

    function num($val = '', $param = null) {
        if ($param == null)
            $param = $this->primaryKey;

        $this->db->from($this->mytable);
		if($val !='')
			$this->db->where($param, $val);
        return $this->db->count_all_results();
    }

    function update($val = '', $param = null, $arr_update) {
        if ($param == null)
            $param = $this->primaryKey;

        if ($val != '')
            $this->db->where($param, $val);
		$arr_update['MAN_TIME_UPDATE'] = time();
        $arr_update = $this->msystem->update_security($arr_update, $this->field());
        $this->db->update($this->mytable, $arr_update);
    }

    function insert($arr_insert) {
        $arr_insert = $this->msystem->insert_security($arr_insert, $this->field());
        $this->db->insert($this->mytable, $arr_insert);
        return $this->db->insert_id();
    }

    function delete($val = '', $param = null) {
        if ($val != '') {
            $this->db->where($param, $val);
            $this->db->delete($this->mytable);
        }
    }
	
	function create_file_temp(){
		$this->load->helper('file');
		$data = "<?php \n";
        $data.="return ";
        $cate = $this->gets();
        $cate_new = array();
        for($i=0; $i<count($cate); $i++){
            $data_cate = $cate[$i];
            $cate_new[$data_cate->MAN_ID] = (array)$data_cate;
            unset($data_cate);
        }
        $data_temp = var_export($cate_new, true);
        $data.= $data_temp;
        $data.="?>\n";
        write_file('./'.$this->folderCache.'manufacturer.php', $data);
	
	}
}

?>